package zhou.chs.p2_6;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView tv;     //声明TextView控件，显示联锁开关状态
    Switch sw;       //声明1个Switch控件，作为联锁开关
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=(TextView)findViewById(R.id.idtv);
        sw=(Switch)findViewById(R.id.idsw);
        sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    tv.setText("联锁投入");
                }
                else{
                    tv.setText("联锁退出");
                }
            }
        });
    }
}
